﻿using Best.SmartCms.Domain;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Dto;
using Best.SmartCms.Service;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    /// <summary>
    /// Role
    /// </summary>
    public class RoleController : Controller
    {
        private readonly RoleService _roleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleService"></param>
        public RoleController(RoleService roleService)
        {
            _roleService = roleService;
        }


        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("role/pagelist")]
        public PagedResponse<RoleListDto> PageList([FromBody]RoleListQueryDto query)
        {
            var ret = _roleService.PageList(query);
            return ret;
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("role/create")]
        public ApiResponse Create([FromBody]RoleEditDto dto)
        {
             _roleService.Create(dto);
            return ApiResponse.Succeeds();
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("role/edit")]
        public ApiResponse Edit([FromBody]RoleEditDto dto)
        {
            _roleService.Edit(dto);
            return ApiResponse.Succeeds();
        }


        /// <summary>
        /// 详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("role/Info")]
        public ApiResponse<RoleEditDto> Info(long id)
        {
            var ret = _roleService.Info(id);
            return ApiResponse<RoleEditDto>.Succeeds(ret);
        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("role/delete")]
        public ApiResponse Delete(long id)
        {
            _roleService.Delete(id);
            return ApiResponse.Succeeds();
        }
    }
}